#include "stdio.h"
#include "unistd.h"
#include "sys/time.h"

int num_sqr(int num)
{
    sleep(1);
    return num * num;
}

int main(int argc, char const *argv[])
{
    int nums[5] = {1, 2, 3, 4, 5};

    struct timeval start, end;

    gettimeofday(&start, NULL);
    int sum = 0;
    for (int i = 0; i < 5; i++)
    {
        sum += num_sqr(nums[i]);
    }
    gettimeofday(&end, NULL);

    printf("平方和 Sum = %d \n", sum);
    printf("计算总时长为:%ld \n", end.tv_sec - start.tv_sec);

    return 0;
}
